

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layuiAdmin 内容系统 - 文章列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../layuiadmin/style/admin.css" media="all">
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-row" style="padding-bottom: 50px;">
            <div class="layui-col-md2">
                <div id="test_tree"></div>
            </div>
            <div class="layui-col-md10">
                <div class="layui-card-body">
                    <div style="padding-bottom: 10px;">
                        <button class="layui-btn layuiadmin-btn-list" data-type="batchdel">删除</button>
                        <button class="layui-btn layuiadmin-btn-list" data-type="add">添加</button>
                    </div>
                    <table id="table_temp_id" lay-filter="table_temp_id"></table>
                </div>
            </div>
        </div>
    </div>
</div>



<script type="text/html" id="table-content-list">
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
</script>
<script src="../../layuiadmin/js/jquery.min.js"></script>
<script src="../../layuiadmin/layui/layui.all.js"></script>
<script src="../../layuiadmin/js/lx.js"></script>
<script>
    layui.tree.render({
        elem: '#test_tree'
        ,data: []
        ,id: 'test_tree'
        ,onlyIconControl:true //点图标收缩
        ,click: function(obj){
            show_id = obj.data.id;
            dataObj.search();
        }
        ,text: {
            defaultNodeName: '未命名' //节点默认名称
            ,none: '无数据' //数据为空时的提示文本
        }
    });
    var show_id = "0";
    dataObj.table_temp.url = lx.wwwroot+'sys/list/menu';
    dataObj.table_temp.page = false;
    dataObj.edit_area=['600px', '650px'];
    dataObj.add_area=['600px', '650px'];
    dataObj.rows_filter= function(rows){
        var ls = layui_fun.arrayToTree(rows,'0',function (item) {
            item.title = item.name;
            item.spread = true;
        });
        layui.tree.reload('test_tree', {data:ls});
        return rows.filter(function (v) {
            return v.id == show_id || v.pid == show_id;
        });
    }
    dataObj.table_temp.cols=[[
        {type:"checkbox",fixed:"left"}
        ,{field:"id",title:"ID",width:100}
        ,{field:"name",width:200,title:"菜单名",sort:!0,align:"center",templet:function (v) {
            return v.type==3?`<button class="layui-btn layui-btn-primary layui-btn-xs">${v.name}</button>`: `<button class="layui-btn layui-btn-xs" lay-event="add_p">${v.name}</button>`;
        }}
        ,{field:"type",width:100,title:"类型",sort:!0,align:"center",templet:function (v) {
            return v.type==3?`<button class="layui-btn layui-btn-xs layui-btn-danger">按钮</button>`: v.type==2?`<button class="layui-btn layui-btn-xs layui-btn-warm">菜单</button>`:`<button class="layui-btn layui-btn-xs layui-btn-normal">目录</button>`;
        }}
        ,{field:"pid",width:100,title:"父菜ID",sort:!0}
        ,{field:"p_name",width:200,title:"父菜单名",sort:!0}
        ,{field:"address",width:200,title:"菜单地址",sort:!0}
        ,{field:"status",title:"状态",width:100,align:"center",t1:'有效',t2:'无效',templet:temp_fun.sex_func,sort:!0}
        ,{title:"操作",minWidth:150,align:"center",fixed:"right",toolbar:"#table-content-list"}
    ]];
    dataObj.del=function (data) {
        lx.ajax("sys/del/menu",dataObj.del_success,{id:data.id});
    };
    dataObj.edit = function (data) {
        return 'edit.html?id='+data.id;
    };
    dataObj.add_p=function (data) {
        return 'edit.html?pid='+data.id;
    };
    dataObj.add_p_area=['600px', '650px'];
    dataObj.add_content='edit.html';
    dataObj.delAll = function (checkData) {
        var id = '';
        for(var i in checkData){
            var v = checkData[i];
            id+=id.length>0?','+v.id : v.id;
        }
        layer.confirm('确定删除吗？', function(index) {
            lx.ajax("sys/del/menu",dataObj.del_success,{id:id});
        });
    }
</script>
</body>
</html>
